﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EmptyASP.View
{
    public partial class imagePreviewPanel : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            try
            {
                SqlConnection myConn = new SqlConnection();
                myConn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["database"].ConnectionString;
                myConn.Open();
                string strQuery = "SELECT id, filename FROM Images ORDER BY id DESC";
                SqlCommand myCom = new SqlCommand(strQuery, myConn);
                SqlDataReader dr = myCom.ExecuteReader();
                while (dr.Read())
                {
                    int id = (int)dr["id"];
                    String filename = (String)dr["filename"];
                    imagePreview ip = (imagePreview)Page.LoadControl("~/View/imagePreview.ascx");
                    ip.imageURL = "/image.ashx?id=" + id;
                    ip.imageFilename = filename;
                    imagePreviewPan.Controls.Add(ip);
                }
                dr.Close();
                myConn.Close();
            }
            catch
            {
                ErrorLabel.Text = "BŁĄD BAZY DANYCH";
            }
        }
    }
}